export function debounce(f, delay = 500, immediate = true) {
  let waiting = false,
    clock
  return function () {
    if (!waiting) {
      waiting = true
      immediate && f.apply(this, arguments)
    }
    clearTimeout(clock)
    clock = setTimeout(() => {
      waiting = false
      !immediate && f.apply(this, arguments)
    }, delay)
  }
}
